﻿<!doctype html>
 <html lang="zh-CN">
 <head>
   <meta charset="UTF-8">
   <link rel="stylesheet" href="${req.contextPath}/css/common.css">
   <link rel="stylesheet" href="${req.contextPath}/css/main.css">
   <script type="text/javascript" src="${req.contextPath}/js/jquery.min.js"></script>
   <script type="text/javascript" src="${req.contextPath}/js/colResizable-1.3.min.js"></script>
   <script type="text/javascript" src="${req.contextPath}/js/common.js"></script>

</head>
<body>
        <div  class="box_bottom pb5 pt5 pr10" style="border-top:1px solid #dadada;">
              <div class="search_bar_btn" style="text-align:left;" >
                 <a href="${req.contextPath}/administrative/reserveCar-ui" class="ext_btn"><span class=""></span>用车预定</a>
              </div>
            </div>

        <#if user.roleId==8>
             <div  class="box_bottom pb5 pt5 pr10" style="border-top:1px solid #dadada;">
              <div class="search_bar_btn" style="text-align:center;" >
                 <a href="${req.contextPath}/administrative/saveCar-ui" class="ext_btn"><span class="add"></span>添加车辆</a>
              </div>
            </div>
        </#if>
			
<form>
 <div id="table" class="mt10">
        <div class="box span10 oh">
              <table id="Tab" width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table">
                <tr>
				   <th> <input type="checkbox" id="checkall" onclick="checkAll()"></th>
                   <th>车牌号</th>
                   <th>车型</th>
				   <th>颜色</th>
				   <th>备注</th>
                    <#if user.roleId==8>
				   <th>操作</th>
                    </#if>
                    </tr>
               <#list pageInfo.list as list>
                <tr  class="tr" align="center">
                   <td class="td_center" name='id'><input type="checkbox" name='id' value="${list.carId}" onclick="docheck()" /></td>
                   <td>${list.numCard}</td>
                   <td>${list.vehicleType}</td>
				   <td>${list.vehicleColor}</td>
				   <td>${list.content}</td>
                    <#if user.roleId==8>
				   <td>
					  <a href="${req.contextPath}/administrative/update-ui?id=${list.carId}&page=${pageInfo.getPageNum()}">编辑</a> |&nbsp;
					  <a href="javascript:void(0)" onclick="del(${list.carId})">删除</a>
				   </td>
                    </#if>
                 </tr>
               </#list>
               <tr>
			   <td colspan="2">
                   <#if user.roleId==8>
                   <input type="button" class="btn btn82 btn_del" value="删除" onclick="delAll()">
                   </#if>
                   <input type="button" name="button"  class="btn btn82 btn_export" value="导出" onclick="excel()">
				</td>
				<td colspan="5" align="right">
				     <div class="page mt10">
						<div class="pagination">
						  <ul >
							  <li class="first-child"><a href="${req.contextPath}/resource/xingzheng/demo2/list">首页</a></li>
                              <#if pageInfo.getPrePage() lt 1>
                                  <li>
                                      <a href="${req.contextPath}/resource/xingzheng/demo2/list?page=1">上一页</a>
                                  </li>
                              <#else >
                                  <li>
                                      <a href="${req.contextPath}/resource/xingzheng/demo2/list?page=${pageInfo.getPrePage()}">上一页</a>
                                  </li>
                              </#if>

                              <#if pageInfo.getNextPage() == 0>
                                  <li>
                                      <a href="${req.contextPath}/resource/xingzheng/demo2/list?page=${pageInfo.getPages()}">下一页</a>
                                  </li>
                              <#else >
                                  <li>
                                      <a href="${req.contextPath}/resource/xingzheng/demo2/list?page=${pageInfo.getNextPage()}">下一页</a>
                                  </li>
                              </#if>
							  <li ><a href="${req.contextPath}/resource/xingzheng/demo2/list?page=${pageInfo.getPages()}">末页</a></li>
                              <li ><span>共${pageInfo.total}条数据</span></li>
                              <li ><span>共${pageInfo.getPages()}页</span></li>
						  </ul>
						</div>
                     </div>
				</td>
			   </tr>
              </table>
        </div>
     </div>
</form>
     <script type="text/javascript" src="${req.contextPath}/js/jquery.min.js"></script>
     <script>

         var checkall, item;
         checkall = document.getElementById("checkall");
         item = document.getElementsByName("id");
         //全选框判断：全选 全不选
         function checkAll() {
             for (var i = 0; i <item.length; i++) {
                 if(checkall.checked){
                     item[i].checked = true;
                 }else{
                     item[i].checked = false;
                 }
             }
         }
         //单选框判断:如果单选框被选中的数量和单选框的数量相等的时候全选框选中，反之没有被选中；
         function docheck(){
             var count=0;
             for (var i = 0; i <item.length ; i++) {
                 if(item[i].checked){
                     count++;
                 }
             }
             if(count===item.length){
                 checkall.checked = true;
             }else{
                 checkall.checked = false;
             }
         }

         //批量删除
         function delAll() {
             var chk_value =[];//定义一个数组
             $('input[name="id"]:checked').each(function(){//遍历每一个名字为id的复选框，其中选中的执行函数
                 chk_value.push($(this).val());//将选中的值添加到数组chk_value中
             });
             if (chk_value.length==0){
                 alert("请先选择要删除的数据");
                 return;
             }
             $.post(
                 "${req.contextPath}/administrative/delAll",
                 {ids:chk_value},
                 function (result) {
                     if (result.code == 0) {
                         alert("删除成功");
                         location.href = "${req.contextPath}/resource/xingzheng/demo2/list";
                     } else {
                         alert(result.msg)
                     }
                 },
                 "json"
             );
         }

         //导出
         function excel() {
             var chk_value =[];//定义一个数组
             $('input[name="id"]:checked').each(function(){//遍历每一个名字为id的复选框，其中选中的执行函数
                 chk_value.push($(this).val());//将选中的值添加到数组chk_value中
             });
             if (chk_value.length==0){
                 alert("请先选择要导出的数据");
                 return;
             }

             location.href="${req.contextPath}/administrative/excel?ids="+chk_value;
         }


         //单个删除
         function del(id) {
             if (confirm("确定要删除这条信息吗")) {
                 $.post(
                     "${req.contextPath}/administrative/del?id=" + id,
                     null,
                     function (result) {
                         if (result.code == 0) {
                             alert("删除成功");
                             location.href = "${req.contextPath}/resource/xingzheng/demo2/list";
                         } else {
                             alert(result.msg)
                         }
                     },
                     "json"
                 );
             }
         }
         

     </script>
</body>
</html>